const express = require("express");
const router = express.Router();
const User = require("../database/models/user");
const signinjian = require("../middlewares/signinjian");

// 注册功能
router.post("/", [signinjian], async function (req, res) {
  const account = req.body.account;
  const data = await User.findAll({
    where: {
      account: account
    }
  });
  console.log(data);
  if (data[0]) {
    if (data[0].dataValues.account === account) {
      return res.status(400).send({
        Informationerror: "该账号已存在！"
      });
    }
  }
  //否则添加到数据库
  await User.create({ account: req.body.account, password: req.body.password });
  return res.status(200).send({ good: "注册成功！" });
});
// 导出api(路径)
module.exports = router



